<template>
	<view>
		<!-- 店铺信息 -->
		<view class="uni-flex uni-row uni-bg-white" 
			style="padding: 32rpx 0;padding: 30rpx 32rpx;">
			<view>
				<image style="width:150rpx;height:150rpx; border-radius:5%;" 
					src="../../static/image/hlk.jpg"></image>
			</view>
			<view class="uni-flex uni-column" style="margin-left:32rpx;font-size:26rpx;flex: 1 1 0%;justify-content: space-between;">
				<view style="font-size:34rpx;">
					<text>{{merchant.name}}</text>
				</view>
				<view style="color:#595959;">
					<view>
						<text>{{merchant.address}}</text>
					</view>
					<view>
						<text>客服电话：{{merchant.phone}}</text>
					</view>
				</view>
			</view>
			<view style="display:flex;align-items:center;justify-content:center;" 
				@click="onService">
				<image style="width:60rpx;height:60rpx;" src="../../static/image/tel.png"></image>
			</view>
		</view>
		
		<view>
			<!-- 各门店 -->
			<view class="uni-bg-white lig-card">
				<view class="lig-card-title">
					<text>短途快运</text>
				</view>
				<view @click="toPublish" 
					style="border-bottom: 2rpx solid #f5f5f5;padding:20rpx 20rpx;color:#595959;font-size:11pt;"
					v-for="it in shopList" :data-shop-id="it.name">
					{{it.name}}
				</view>
			</view>
			
			<!-- 专线直达 -->
			<view class="uni-flex uni-column uni-bg-white lig-card">
				<view class="lig-card-title">
					<text>专线直达</text>
				</view>
				<view style="border-bottom: 2rpx solid #DDDDDD;padding:20rpx 20rpx;color:#7B7B7B;font-size:11pt;"
					v-show="directList.length <= 0">
					即将上线，敬请期待
				</view>
				<view @click="toPublish"
					style="border-bottom: 2rpx solid #DDDDDD;padding:20rpx 20rpx;color:#7B7B7B;font-size:11pt;"
					v-for="it in directList" :data-shop-id="it.name">
					{{it.name}}
				</view>
			</view>
			<view style="padding: 20rpx 0;"></view>
		</view>
	</view>
	
</template>

<script>
	import {} from '@/util/constant.js';
	import { post, $get, checkLogin, getUserId } from '@/util/request.js'
	export default {
		data() {
			return {
				shopList: [],
				merchant: {
					id: 0,
					name: '海陆空物流专家',
					phone: '15958152322',
					address: '许村',
					avatar: ''
				},
				directList: [
				]
			}
		},
		onLoad() {
			wx.showShareMenu({
			    withShareTicket:true,
			    // 设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
			    menus:["shareAppMessage","shareTimeline"]
			});
			
			this.getShopList();
			this.getMerchantInfo();
			this.getRouteList();
		},
		// 转发给好友
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		    }
		    return {
		        title: APP_NAME //分享的名称
		    }
		},
		//分享到朋友圈
		onShareTimeline(res) {
		    return {
		        title: APP_NAME,
		        type: 0,
		        summary: ''
		    }
		},
		methods: {
			async toPublish() {
				let res = await checkLogin();
				if (!res) {
					uni.reLaunch({
						url: '/pages/login/login'
					});
				} else {
					uni.navigateTo({
						url: '/pages/publish/publish'
					});
				}
			},
			getShopList() {
				let that = this;
				post('express/shop/list', {}).then(res => {
					// this.shopList = res.data;
					for (let index in res.data) {
						let shop = res.data[index];
						if (typeof shop.type != 'undefined' && shop.type == 1) {
							that.shopList.push(shop);
						}
					}
				});
			},
			getRouteList() {
				let that = this;
				let userId = getUserId();
				if (userId == null || userId == '') {
					uni.reLaunch({
						url: '/pages/login/login'
					});
				} else {
					post('express/cargo/list/v2', {
						userId: userId
					}).then(res => {
						if (res.success) {
							for (let key in res.data) {
								let route = res.data[key];
								if (typeof route.type != 'undefined' && route.type == 2) {
									that.directList.push({
										name : route.name
									});
								}
							}
						}
					});
				}
			},
			onService() {
				
				uni.makePhoneCall({
					phoneNumber: this.merchant.phone,//电话号码
					success:function(e){
					},
					fail:function(e){
				
					}
				});
			},
			onNavigateJob() {
				wx.navigateToMiniProgram({
				  appId: 'wxf166ec2028c943c8',
				  success(res) {
				    // 打开成功
				  }
				});
			},
			getMerchantInfo() {
				$get('express/merchant/info', {}).then(res => {
					this.merchant = res.data;
				});
			}
		}
	}
</script>

<style>
@import url("../../common/uni.css");
</style>
